package mq

import (
	"context"

	"gitee.com/mkwchecking/sr-core/yerr"
)

var (
	// 默认 mq 引擎未找到
	ErrMQEngineNotFound = yerr.NewCode(yerr.ErrBizPluginNotFound)
)

func Default() (IMsgQueue, bool) {
	return _mqSet.GetDefault()
}

func Publish(ctx context.Context, msg MQMessage) error {
	mq, ok := Default()
	if !ok {
		return ErrMQEngineNotFound
	}
	return mq.Publish(ctx, msg)
}

func Subscribe(ctx context.Context, topic string, handlers ...IMsgHandler) error {
	mq, ok := Default()
	if !ok {
		return ErrMQEngineNotFound
	}
	return mq.Subscribe(ctx, topic, handlers...)
}

func Unsubscribe(ctx context.Context, topic string, handlers ...IMsgHandler) error {
	mq, ok := Default()
	if !ok {
		return ErrMQEngineNotFound
	}
	return mq.Unsubscribe(ctx, topic, handlers...)
}
